package com.wangxinenpu.springbootdemo.controller;

import com.baomidou.mybatisplus.extension.api.R;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wangxinenpu.springbootdemo.dataobject.dto.function.FunctionTreeVo;
import com.wangxinenpu.springbootdemo.dataobject.dto.role.RoleDto;
import com.wangxinenpu.springbootdemo.dataobject.dto.role.RoleFunDto;
import com.wangxinenpu.springbootdemo.dataobject.model.Function;
import com.wangxinenpu.springbootdemo.dataobject.model.Role;
import com.wangxinenpu.springbootdemo.service.RoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping ( "/role" )
@AllArgsConstructor
@Api ( value = "角色管理", tags = "角色管理" )
@Slf4j
public class RoleController {

	private final RoleService roleService;

	@PostMapping ( "/pageList" )
	@ApiOperation ( value = "角色管理列表", notes = "角色管理列表" )
	public R < Page < Role > > pageList ( @RequestBody RoleDto dto ) {
		return roleService.pageList ( dto );
	}

	@PostMapping ( "/delete" )
	@ApiOperation ( value = "删除/批量删除", notes = "删除/批量删除" )
	public R < Boolean > delete ( @RequestBody List < String > ids ) {
		return roleService.delete ( ids );
	}

	@PostMapping ( "/saveOrUpdate" )
	@ApiOperation ( value = "新增/编辑", notes = "新增/编辑" )
	public R < Boolean > saveOrUpdate ( @RequestBody @Validated RoleDto dto ) {
		return roleService.saveOrUpdate ( dto );
	}

	@PostMapping ( "/configurationFunction" )
	@ApiOperation ( value = "配置功能点", notes = "配置功能点" )
	public R < Boolean > configurationFunction ( @RequestBody @Validated RoleFunDto dto ) {
		return roleService.configurationFunction ( dto );
	}

	@GetMapping ("detail")
	@ApiOperation ( value = "详情", notes = "详情" )
	public R < Role > detail ( @RequestParam String id) {
		return R.ok( roleService.getById( id ) );
	}


	@GetMapping ("treeFun")
	@ApiOperation ( value = "功能点树", notes = "功能点树" )
	public R < List<FunctionTreeVo> > treeFun ( @RequestParam String id) {
		return  roleService.treeFun( id );
	}

}
